/*
 * Copyright (C) 2010 Young, Fey <fey.young@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package com.youngfey.ebs

import org.junit.*
import static org.junit.Assert.*

/**
 * @author Young, Fey <fey.young@gmail.com>
 */
class AnalystTest {
    @Before
    void setUp() {
analyst = new Analyst()
        analyst.estimates = estimates
    }

    
    def analyst

    //STEP 1 - 1:0.75; 2:1
    //SETP 2 - 2:0.25; 3:1
    //SETP 3 - 3:0.25; 5:0.75; 6:1
    //SETP 4 - 4:0.25; 6:0.5; 7:0.75; 10:1
    def estimates = [
        [1, 2, 3, 4],
        [1, 1, 1, 1],
        [1, 2, 1, 2],
        [2, 1, 2, 1]
    ]

    @Test
    void testMaxSteps() {
        assertEquals 4, analyst.maxStep
    }

    @Test
    void testGetProbability() {
        assertEquals 0, analyst.getProbability(1, 1)
        assertEquals 0.25, analyst.getProbability(1, 2), 0.001
        assertEquals 1, analyst.getProbability(1, 3), 0.001
        assertEquals 1, analyst.getProbability(1, 4)
        assertEquals 0.8125, analyst.getProbability(3, 7), 0.001
        assertEquals 0.5, analyst.getProbability(3, 5), 0.001
    }

    @Test
    void testGetEstimate() {
        assertEquals 1, analyst.getEstimate(0, 0.25), 0.001
        assertEquals 2.1667, analyst.getEstimate(1, 0.375), 0.001
        assertEquals 3, analyst.getEstimate(1, 1), 0.001 // max

        assertEquals 2, analyst.getMinEstimate(1)
        assertEquals 10, analyst.getMaxEstimate(3)
    }
}
